<%-- 
    Document   : joinCircle
    Created on : Dec 8, 2011, 7:59:44 PM
    Author     : Owner
--%>

<%@page import="javax.swing.JOptionPane"%>
<%@page import="java.sql.*"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<% if(session.getAttribute("LoggedIn")==null)
       {
    response.sendRedirect("index.html");
    return;
        }

%>
<%
    int circleID = Integer.parseInt(session.getAttribute("CIRC").toString());
    int userID = Integer.parseInt(session.getAttribute("UserID").toString());
    int ownerID = Integer.parseInt(session.getAttribute("Owner").toString());
    session.removeAttribute("Owner");
    session.removeAttribute("circleID");
    session.removeAttribute("CIRC");
    
    Connection conn = null;
    try
    {
        conn = new DBClasses.GetConnection().getConnection();
        String query = "INSERT INTO tentatives (CircleID, CircleOwner, CustomerID, CustomerApproved) " + 
                "VALUES (?, ?, ?, ?)";
        PreparedStatement ps = conn.prepareStatement(query);
        ps.setInt(1, circleID);
        ps.setInt(2, ownerID);
        ps.setInt(3, userID);
        ps.setInt(4, 1);
        
        ps.execute();
        
        
        
    }
    catch(Exception e)
    {
        e.printStackTrace();
        response.sendRedirect("gohome.jsp");
    }
    finally
    {
        try{
        conn.commit();
        conn.close();
        JOptionPane.showMessageDialog(null, "A request has been sent");
        response.sendRedirect("gohome.jsp");
               }
        
        catch(Exception e)
    {
        e.printStackTrace();
        response.sendRedirect("gohome.jsp");
    }
    }
%>
